
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:library_base/ext/bool_ext.dart';
import 'package:library_base/ext/theme_data_ext.dart';
import 'package:library_base/global/multi_language.dart';
import 'package:library_base/res/dividing_line.dart';
import 'package:library_base/res/gaps.dart';
import 'package:library_base/res/geometry.dart';
import 'package:library_base/res/styles.dart';
import 'package:library_base/res/widget_generator.dart';
import 'package:library_base/utils/sp_util.dart';
import 'package:library_base/utils/theme_util.dart';
import 'package:library_base/widget/button/gradient_button.dart';
import 'package:library_base/widget/image/local_image.dart';
import 'package:library_base/utils/get_util.dart';

/// 商品信息录入的dialog
class CommodityInfoEntryDialog extends StatefulWidget {
  const CommodityInfoEntryDialog({
    Key? key,
  }) : super(key: key);

  @override
  State<CommodityInfoEntryDialog> createState() =>
      _CommodityInfoEntryDialogState();
}

class _CommodityInfoEntryDialogState extends State<CommodityInfoEntryDialog> {
  ///主商品(边猪)重量
  final TextEditingController mainWeightController = TextEditingController();
  final FocusNode mainWeightFocusNode = FocusNode();

  ///辅商品(下水)重量
  final TextEditingController minorWeightController = TextEditingController();
  final FocusNode minorWeightFocusNode = FocusNode();

  ///回调函数
  ///parameter1：主商品(边猪)重量
  ///parameter2：辅商品(下水)重量
  void Function(double, double)? callback;

  bool enableConfirm = false;

  @override
  void initState() {
    super.initState();
    var arguments = Get.arguments;
    callback = arguments['CallBack'];
    mainWeightController.text = arguments['main_weight'].isNotZeroAndNull()
        ? arguments['main_weight'].toString()
        : '';
    minorWeightController.text = arguments['minor_weight'].isNotZeroAndNull()
        ? arguments['main_weight'].toString()
        : '';
  }

  @override
  Widget build(BuildContext context) {
    return Material(
      color: Colors.transparent,
      child: WillPopScope(
        onWillPop: () {
          GetHelper.back();
          return Future.value(false);
        },
        child: GestureDetector(
          onTap: () => Get.back(),
          child: Container(
            alignment: Alignment.center,
            color: Colors.transparent,
            child: roundWidget(
                width: 0.8.sw,
                child: Column(
                  mainAxisSize: MainAxisSize.min,
                  children: [
                    Stack(
                      children: [
                        Container(
                            padding: EdgeInsets.only(top: 40.w, bottom: 24.w),
                            width: double.infinity,
                            alignment: Alignment.center,
                            child: Text(MultiLanguage.commodityInformationEntry.tr,
                                style: normalTextColor34)),
                        Positioned(
                          child: GestureDetector(
                            onTap: () {
                              GetHelper.back();
                            },
                            child: Container(
                              padding: EdgeInsets.only(
                                  right: 40.w,
                                  left: 40.w,
                                  bottom: 29.w,
                                  top: 40.w),
                              child: LocalImage('common_close',
                                  width: 26.r, height: 26.r),
                            ),
                          ),
                        )
                      ],
                    ),
                    line1,
                    Row(
                      children: [
                        Expanded(
                            flex: 2,
                            child: Container(
                              alignment: Alignment.centerRight,
                              child: Text(MultiLanguage.barcode.tr,
                                  style: normalTextColor28),
                            )),
                        gapW18,
                        Expanded(
                            flex: 3,
                            child: Text('M102', style: normalTextColor28)),
                      ],
                    ),
                    gapH24,
                    Row(
                      children: [
                        Expanded(
                            flex: 2,
                            child: Container(
                              alignment: Alignment.centerRight,
                              child: Text(MultiLanguage.weightMain.tr,
                                  style: normalTextColor28),
                            )),
                        gapW18,
                        Expanded(
                            flex: 3,
                            child: inputInfo(
                                controller: mainWeightController,
                                focusNode: mainWeightFocusNode,
                                borderRadius: geometry30,hintText: "${MultiLanguage.pleaseInputWeight.tr}${SPUtil.isJin.unitStrZhWithBracket()}")),
                      ],
                    ),
                    gapH24,
                    Row(
                      children: [
                        Expanded(
                            flex: 2,
                            child: Container(
                              alignment: Alignment.centerRight,
                              child: Text(MultiLanguage.complementaryGoodsWeight.tr,
                                  style: normalTextColor28),
                            )),
                        gapW18,
                        Expanded(
                            flex: 3,
                            child: inputInfo(
                                controller: mainWeightController,
                                focusNode: mainWeightFocusNode,
                                borderRadius: geometry30,hintText: MultiLanguage.pleaseInputWeight.tr)),
                      ],
                    ),
                    gapH40,
                    line1,
                    gapH24,
                    GradientButton(
                      ThemeUtil.getTheme(),
                      colors: ThemeUtil.getTheme().buttonRight1BgColor(),
                      width: double.infinity,
                      height: 77.w,
                      text: MultiLanguage.determine.tr,
                      onPressed: enableConfirm ? _confirm : null,
                    ),
                    gapH24,
                  ],
                )),
          ),
        ),
      ),
    );
  }

  ///确定录入信息
  _confirm(){

  }

}
